@model FunnelWeb.Web.Areas.Admin.Views.Install.IndexModel
@{
  ViewBag.Title = "FunnelWeb Installation";
  Layout = "~/Areas/Admin/Views/Shared/_Private.cshtml";

  var properNoun = Model.IsInstall ? "Installer" : "Upgrader";
  var noun = Model.IsInstall ? "installer" : "upgrader";
  var verb = Model.IsInstall ? "install" : "upgrade";
  var proceed = Model.IsInstall ? "Proceed with Installation" : "Proceed with Upgrade";
}
<h1>
  FunnelWeb @properNoun
</h1>
<p class='important'>
  Welcome to your FunnelWeb installation!
</p>
<p>
  This page allows you to edit the SQL Server connection string, and install or upgrade
  the database. You will see this page any time you upgrade FunnelWeb.
</p>
<h2>
  Change Connection String</h2>
@if (Model.CanConnect)
{
  <p class='good'>
    The connection string below appears to work. However, you can change it if you wish
    to use an alternative database.
  </p>
}
else
{
  <p class='bad'>
    The connection string below is invalid. You will need to change it before proceeding
    with this @verb. The error was:
  </p>
  <pre>@Model.ConnectionError</pre>
}
@using (Html.BeginForm("Test", "Install", FormMethod.Post, new { Area = "Admin" }))
{
  <div class="form-body">
    <div class="editor-label">
      @Html.LabelFor(m => m.ConnectionString)
    </div>
    <div class="editor-field">
      @Html.TextAreaFor(m => m.ConnectionString, Html.AttributesFor(m => m.ConnectionString))
      @Html.ValidationMessageFor(m => m.ConnectionString)
      @Html.HintFor(m => m.ConnectionString)
    </div>
    <div class="editor-label">
    </div>
    <div class="editor-field">
      <input type="submit" id="submit" class="submit" value="Save and Test" />
    </div>
  </div>
}
@if (Model.CanConnect)
{
  <text>
  <h2>@proceed</h2>
  <p>
    The FunnelWeb @noun is now ready to @verb your database.
  </p>

  @if (Model.ScriptsToRun.Length > 0)
  { 
    <p>
      The following scripts will be run against your database. 
    </p>
    
    <ul>
    @foreach (var item in Model.ScriptsToRun)
    {
        <li>@item</li>
    }
    </ul>
  }

  @if (Model.ScriptsToRun.Length == 0)
  {
    <text>
    <p class='good'>Your database is up to date. No @verb is necessary.</p>
    
    <p class='important'><a href="/">Sweet!</a></p>
    </text>
  }
  else
  {
    <text>
    <p class='warning'>
      Reminder: make sure to perform a backup of your database before proceeding with
      this @verb.
    </p>
    @using (Html.BeginForm("Upgrade", "Install", FormMethod.Post))
    {
      <div class="form-body">
        <p>
          @{
            <input type="submit" id="submit1" class="submit" value="@verb" />
          }
        </p>
      </div>
    }
    </text>
  }
  </text>
} 